<template>
        <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="auto" :disabled="disabled">
            <el-form-item label="拟提交会议" prop="type_id">
              <dict-radio  v-model="formData.type_id" dist-key="huiyi_yiti_type"></dict-radio>
            </el-form-item>
            <el-form-item label="议题名称" prop="title">
                <el-input v-model="formData.title" placeholder="请输入议题名字" clearable :style="{width: '100%'}" :disabled="disabled">
                </el-input>
            </el-form-item>
            <el-form-item label="参会人员" prop="meet_user">
                <user-all-select  v-model="formData.meet_user" placeholder="请选择参会人员" :style="{width: '100%'}"  :multiple="true"></user-all-select>
            </el-form-item>
            <el-form-item label="拟列席单位" prop="meet_dept">
                <dept-select-tree v-model="formData.meet_dept" dept-type="all" :style="{width: '100%'}"
                                  placeholder="请选择拟列席单位" :disabled="disabled"  :multiple="true"  :disable-branch-nodes="true"></dept-select-tree>
            </el-form-item>
          <one-row>
            <el-form-item label="提报单位" prop="dept">
              <dept-select-tree v-model="formData.dept" dept-type="my" :style="{width: '100%'}"
                                placeholder="请选择所属单位" :disabled="disabled"></dept-select-tree>
            </el-form-item>
            <el-form-item label="申请人" prop="alias">
                <el-input v-model="formData.alias" placeholder="请输入申请人" :style="{width: '100%'}" disabled>
                </el-input>
            </el-form-item>
          </one-row>
          <el-form-item label="时长(分)" prop="time">
            <el-input-number v-model="formData.time" placeholder="请输入议题时长" clearable :disabled="disabled">
            </el-input-number>
          </el-form-item>
            <el-form-item label="议题内容" prop="content">
                <el-input v-model="formData.content" type="textarea" placeholder="请输入议题内容"
                          :autosize="{minRows: 8, maxRows: 12}" :style="{width: '100%'}"></el-input>
            </el-form-item>
            <el-form-item label="上传附件" prop="files">
                <my-upload-file v-model="formData.files" preview-or-download="download">附件上传</my-upload-file>
            </el-form-item>
        </el-form>
</template>
<script>

    import DeptSelectTree from "@/components/Common/DeptSelectTree";
    import Money from "../../../components/Common/Money";
    import MyUploadFile from "../../../components/Common/MyUploadFile";
    import user from "@/api/systemManagement/user/index";
    import {handleTree,concatChildren} from "@/utils/common";
    import {mapGetters} from "vuex";
    import DictRadio from "../../../components/DictRadio/index";
    import UserAllSelect from "../../../components/Common/UserAllSelect";
    import simpleMeetTopics from "@/api/huiyi/simpleMeetTopics"
    export default {
        components: {UserAllSelect, DictRadio, MyUploadFile, Money, DeptSelectTree,},
        props: ["row", "disabled"],
        data() {
            return {
                formData: {
                    dept:undefined,
                    alias: '',
                    title: undefined,
                    content: undefined,
                    is_draft: 0,
                    type_id:0,
                    meet_dept:[],
                    files:"",
                    meet_user:[],
                    time:30
                },
                rules: {
                    dept: [{
                        required: true,
                        message: '请输入提报单位',
                        trigger: 'blur'
                    }],
                    title: [{
                        required: true,
                        message: '请输入议题名字',
                        trigger: 'blur'
                    }],
                    content: [{
                        required: true,
                        message: '请输入议题内容',
                        trigger: 'blur'
                    }],
                    meet_user: [{
                        required: true,
                        message: '请选择参会人员',
                        trigger: 'change'
                    }],
                    alias: [{
                        required: true,
                        message: '请输入正确姓名',
                        pattern:/^[\u4e00-\u9fa5]{2,}$/,
                        trigger: 'blur'
                    }],
                    // files: [{
                    //     required: true,
                    //     message: '请上传文件',
                    //     trigger: 'change'
                    // }],
                    meet_dept: [{
                        required: true,
                        message: '请选择拟列席单位',
                        trigger: 'change'
                    }],
                },
                userList: [],
                defaultProps: {
                    multiple: true,
                    value: "id",
                    children: "users",
                    label: "alias",
                },
            }
        },
        computed: {
          ...mapGetters(["userinfo"]),
        },
        watch: {

        },
        created() {
            this.formData.alias = this.userinfo.alias;
            this.initData()
            this.getAllDeptsLeaders()
        },
        mounted() {
        },
        methods: {
            initData() {
              if(this.row.id&&!this.row.dept){
                simpleMeetTopics.getDetailInfoById(this.row.id).then(res=>{
                  this.formData = res.data
                })
              }else{
                this.formData = {...this.formData,...this.row}
              }
            },
            getAllDeptsLeaders(){
              user.getAccountsAllUsers({d:'all',r:'all'}).then(res => {
                let list = handleTree(res.data, "id", "parent_dept");
                concatChildren(list)
                this.userList = list;
              });
            },
            submitForm() {
                let self = this
                return new Promise(function (resolve, reject) {
                    self.$refs['elForm'].validate(valid => {
                        if (!valid) return
                        resolve(self.formData)
                    })
                });
            },
            resetForm() {
                this.$refs['elForm'].resetFields()
            },

        }
    }

</script>
<style lang="scss" scoped>
</style>
